package org.jeecg.modules.controller;

import org.jeecg.common.modules.dic.entity.DicCity;
import org.jeecg.common.modules.dic.service.IDicCityService;
import org.jeecg.common.util.enums.AreaLevelEnum;
import org.jeecg.common.util.result.Result;
import org.jeecg.common.util.result.ResultMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1")
public class DicCityController {

    private IDicCityService cityService;

    @RequestMapping("province")
    public Result<List<DicCity>> getProvince()
    {
        List<DicCity> list = cityService.getByLevelAndParentId(AreaLevelEnum.ONE, 1);
        return ResultMapper.<List<DicCity>>ok().setData(list);
    }
    @RequestMapping("city")
    public Result<List<DicCity>> getCity(@RequestParam("provinceId") Integer provinceId){
        List<DicCity> list = cityService.getByLevelAndParentId(AreaLevelEnum.TWO,provinceId);
        return ResultMapper.<List<DicCity>>ok().setData(list);
    }
}
